//
//  PickTheAddBtnViewController.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 16/7/11.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "PickTheAddBtnViewController.h"
#import "ListDetailCell.h"
#import "CustomTextField.h"
#import "KeyNameClass.h"
#import "MyButton2.h"
#import "SexView.h"
#import "SelectSchoolController.h"
#import "OneSelectView.h"
#import "NSString+InputCheck.h"
#import "PickerTimeView.h"
#import "SelectManyView.h"
#import "PickTheAddBtnViewController.h"
#import "KeyValuesClass.h"
#import "EditModel.h"
#import "PicAddListsViewController.h"

@interface PickTheAddBtnViewController (){
    CGFloat             delta;
    CustomTextField     *focusTextField;
    BOOL                added;
    NSMutableArray      *yeaArr;
    NSArray             *monArr;
    NSMutableArray      *daArr;
    NSString            *yeaStr;
    NSString            *montStr;
    NSString            *daStr;
    UIView              *withShowPicView;
    SexView             *sexView;
    MyButton2           *sexBtn;
    BOOL                addSucceed;
    NSMutableArray      *showArr;

}
//@property (strong, nonatomic)NSMutableArray *dataArr;
@property(nonatomic,retain)NSMutableArray               *filedArr;
@property(nonatomic,retain)UIAlertView           *alert;
@property(nonatomic,retain)UIAlertView           *alertSure;

@property(nonatomic,retain)OneSelectView         *oneSelectView;
@property(nonatomic,retain)SelectManyView        *SelectManyView;
@property(nonatomic,assign)NSInteger             indexNum;
@property(nonatomic,retain)UIImageView           *backImg;
@property(nonatomic,retain)NSMutableArray        *textFieldArr;
@property(nonatomic,retain)UIImageView           *timeBackImg;
@property(nonatomic,retain)PickerTimeView        *pickerTime;
@property(nonatomic,retain)NSMutableArray        *defaultArr;
@property(nonatomic,retain)NSMutableDictionary   *selectedDic;   // 已输入的文字显示
@property(nonatomic,retain)NSMutableArray        *needElseChange;   // 已输入的文字显示
@property(nonatomic,retain)NSString              *relationId;   // 关联添加Id
@property(nonatomic,retain)NSMutableArray        *conditionShow;   // 前提条件集成

@property(nonatomic,retain)NSMutableDictionary   *addStyleEqualto3;

@property(nonatomic,retain)NSMutableArray        *hiddenArr;
@property (strong, nonatomic)KeyValuesClass      *keyValueClass;


@property(nonatomic,strong)NSMutableDictionary *selectSchoolKeyValueDic; // 前提条件 Dic

#define SEX 16
@end

@implementation PickTheAddBtnViewController

- (void) keyboardWillShow:(NSNotification *)notify {
    //    UIView *sv = focusTextField.superview;
    
    CGRect rectInTableView = [self.tbView rectForRowAtIndexPath:focusTextField.indexPath];
    CGRect rectInSuperview = [self.tbView convertRect:rectInTableView toView:[self.tbView superview]];
    CGFloat kbHeight = 256;//getKeyboardHeight(notify);
    // 取得键盘的动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGFloat screenHeight = self.view.bounds.size.height;
    //    [UIScreen mainScreen].bounds.size.height;
    
    CGFloat viewBottom = rectInSuperview.origin.y + rectInSuperview.size.height;
    
    if(!added){
        CGSize size = self.tbView.contentSize;
        size.height += 270;
        self.tbView.contentSize = size;
        added = YES;
    }
    
    if (viewBottom + kbHeight < screenHeight)return;
    
    // 键盘会盖住输入框, 要移动整个view了
    //    if (lastIndexPath.row<focusTextField.indexPath.row&&lastIndexPath!=nil) {
    //        delta += viewBottom + kbHeight - screenHeight;
    //
    //    }else{
    //    }
    delta = viewBottom + kbHeight - screenHeight;
    
    
    // masonry的地方了 mas_updateConstraints 更新superView的约束
    //    [self.tbView mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.top.equalTo(@(-delta-30));//.offset(50);
    //    }];
    CGPoint point = self.tbView.contentOffset;
    point.y += delta;
    [UIView animateWithDuration:duration animations:^void(void){
        // superView来重新布局
        self.tbView.contentOffset = point;
        [self.tbView layoutIfNeeded];
    }];
}

- (void) keyboardWillHidden:(NSNotification *)notify {
    // 键盘动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //    [superView mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.top.equalTo(@(0));
    //    }];
    [self.tbView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
    }];
    [UIView animateWithDuration:duration animations:^{
        
        [self.tbView layoutIfNeeded];
    }];
    delta = 0.0f;
    if(added){
        CGSize size = self.tbView.contentSize;
        size.height -= 270;
        self.tbView.contentSize = size;
        added = NO;
    }
    
}




-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    self.subBtn.enabled = YES;
    
    
    
}
-(void)viewDidLoad{
    [super viewDidLoad];
    
    _tNum +=1;
    self.tString =[NSString stringWithFormat:@"t%li", _tNum];

    _hiddenArr = [[NSMutableArray alloc]init];
    
    _needElseChange = [[NSMutableArray alloc]init];
    
    _filedArr = [[NSMutableArray alloc]init];
    
    _conditionShow = [[NSMutableArray alloc]init];
    
    _keyValueClass = [[KeyValuesClass alloc]init];
    
    _sendMutDic = [[NSMutableDictionary alloc]init];
    yeaArr = [[NSMutableArray alloc]init];
    _mangManArr = [[NSMutableArray alloc]init];
    _textFieldArr = [[NSMutableArray alloc]init];
    
    _selectedDic = [[NSMutableDictionary alloc]init];
    
    _addStyleEqualto3 = [[NSMutableDictionary alloc]init];
    _selectedDic = [[NSMutableDictionary alloc]init];
    if (_defaultShowArr.count>0) {
        NSDictionary *dicDefault = [_defaultShowArr valueForKey:@"selectedDic"];
        NSDictionary *dicSendD = [_defaultShowArr valueForKey:@"sendD"];
        NSArray *arrMan = [_defaultShowArr valueForKey:@"mangManD"];
        [_selectedDic setValuesForKeysWithDictionary:dicDefault];
        [_sendMutDic setValuesForKeysWithDictionary:dicSendD];
        [_mangManArr addObjectsFromArray:arrMan];
    }
    
    showArr = [[NSMutableArray alloc]init];
    
    OneSelectView *v = [[OneSelectView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
    [self.view addSubview:v];
    v.backgroundColor = [UIColor redColor];
    
    [self createUI];
    [self currDate];
    
    [self createLeftNavBar];
    [self createRightNavBar];
    [self dataRequest];
    NSLog(@"%@",_dicArr);
    [self setTitleLabelText:@"添加成员"];
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    [noti addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    NSNotificationCenter *noti1 = [NSNotificationCenter defaultCenter];
    [noti1 addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receiveSeleData:) name:@"schools" object:nil];
    _backImg =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
    [_backImg addGestureRecognizer:tap];
    
    [self.view addSubview:_backImg];
    _backImg.backgroundColor =[UIColor colorWithRed:30/255.0 green:32/255.0 blue:40 /255.0 alpha:0.5];
    [self.view bringSubviewToFront:_backImg];
    _backImg.hidden = YES;
    _backImg.userInteractionEnabled = YES;
}


-(void)tapClick{
    _oneSelectView.hidden = YES;
    _oneSelectView.frame = CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200);
    _backImg.hidden = YES;
    
    _SelectManyView.hidden=YES;
    _SelectManyView.frame = CGRectMake(50, 1000, 200, 200);
    _SelectManyView.seleTitle = @"";
    
    
}

#warning mast change
-(void)whileHaveTmpFieldId:(EditModel *)model2 andBaseString:(NSString *)baseString andValue:(NSString *)baseValue{
    for (EditModel *model1 in _needElseChange) { //     for (NSDictionary *dicD in _needElseChange) {
        
        if ([[NSString stringWithFormat:@"%@", model1.tmpFieldId]isEqualToString:[NSString stringWithFormat:@"%@", model2.fieldId]]) { //         if ([[NSString stringWithFormat:@"%@", [dicD valueForKey:@"tmpFieldId"]]isEqualToString:[NSString stringWithFormat:@"%@", [dic valueForKey:@"fieldId"]]]) {
            
            NSLog(@"dic");
            
            //            NSString *str = [dic valueForKey:@"needFilter"];
            //            NSArray *needArr = [str componentsSeparatedByString:@":"];
            
            [self requestNeedElse:model1 andBaseString:baseString andValue:baseValue];
        }
    }
}

-(void)requestNeedElse:(EditModel *)model andBaseString:(NSString *)baseString andValue:(NSString *)baseValue{
    
    
    
    //    NSString *str = [NSString stringWithFormat:@"%@", [dic valueForKey:@"indexPathRow"]];
    
    //    NSInteger inter = [str integerValue];
    NSString *str = [NSString stringWithFormat:@"%@", model.indexPathRow];

    NSInteger inter = [str integerValue];

        CustomTextField *titleText = (CustomTextField *)[self.view viewWithTag:1000+inter];
    
    // ttp://localhost:8081/edus_auto/add_interfaceAjaxGetMaxRule.do?t0_au_70_240_810=12&tableId=70&pageId=240
    NSMutableDictionary *parama = [[NSMutableDictionary alloc]init];
    [parama setObject:baseValue forKey:baseString];
    [parama setObject:[_buttonDic objectForKey:@"startTurnPage"] forKey:@"pageId"];
    [parama setObject:[_buttonDic valueForKey:@"tableId"] forKey:@"tableId"];
    
    [parama setObject: getSessionId() forKey:@"sessionId"];
    
    NSString *requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, TMPREQUEST_URl];
    [NetRequest requestUrl:requestStr andParamas:parama andReturnBlock:^(NSData *data, NSError *error) {
        if (!error&&data!=nil) {
            
            NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"%@", obj);
            
            if ([obj valueForKey: @"promptMessage"]) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"relogin" object:@"relogin"];
                
            }
            
            if (str) {
                
                model.true_defaultShowValName = str;
                
                //                titleText.text = str;
                
                //                NSDictionary *dic= [_filedArr objectAtIndex:titleText.indexPath.row];
                //                NSString *fieldRole= [dic objectForKey:@"fieldRole"];
                //                NSString *fieldId= [dic objectForKey:@"fieldId"];
                //                NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
                //*** change the tableId
                //                NSString *tableId= [_buttonDic objectForKey:@"tableId"];
                //                NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
                NSString *role =[NSString stringWithFormat:@"%@",model.fieldRole];
                
//                NSString *baseString = [_keyValueClass makeTheBaseString:model andTheEditDic:_buttonDic]; // [self makeTheBaseString:dic]
                
                BOOL is = [NSString witchRoleis:role withStr:model.true_defaultShowValName];
                if(is){
                    
                    [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                    NSLog(@"%@",_sendMutDic);
                    
                                        [_selectedDic setObject:titleText.text forKey:[NSString stringWithFormat:@"%ld", (long)titleText.indexPath.row]];
                }
            }
        }else{
            NSString *string = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:string];
        }
    }];
}


#pragma mark receive data of schoolList
-(void)receiveSeleData:(NSArray *)arr{
    CustomTextField *titleText = (CustomTextField *)[self.view viewWithTag:1000+_rowNum];
    titleText.hidden = NO;
    
    NSString *titleStr;
    NSString *iDString;
    if(arr.count>1){
        
        titleStr = [arr[0] componentsJoinedByString:@","];
        iDString = [arr[1] componentsJoinedByString:@","];
    }else{
        titleStr = @"";
        iDString = @"";
    }
    titleText.text = titleStr;
    
    EditModel *model = _filedArr[_rowNum];
    model.true_defaultShowValName = titleStr;
    model.true_defaultShowValId = iDString;
    //*** 键拼接 方法可能数据请求中也需要用 所以做了个简单的封装
    
    [_keyValueClass whileFieldRowTypeIsspeciall:model andTnum:_tNum andTstring:self.tString andSendMutDic:_sendMutDic andManyMan:_mangManArr andEditDetailDic:_buttonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, NSDictionary *dicDEdit, EditModel *model211){
        _sendMutDic = send;
        _mangManArr = manyman;
        _buttonDic = dicDEdit;
        //        [_fieldArrText replaceObjectAtIndex:_rowsNum withObject:model211];
    }];
    
    //    [self whileFieldRowTypeIsspeciall:model];
    
    [self.tbView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:titleText.indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
    
    
    //    NSArray *arr =[notify object];
    
    
    //    NSString *titleStr = [arr[0] componentsJoinedByString:@","];
    //    NSString *numStr = [arr[1] componentsJoinedByString:@","];
    //    titleText.text = titleStr;
    
    //*** receive show
        [_selectedDic setObject:titleStr forKey:[NSString stringWithFormat:@"%ld", (long)titleText.indexPath.row]];
    
    //    NSDictionary *dic= [_filedArr objectAtIndex:_rowNum];
    
    
    //    NSString *fieldRole= [dic objectForKey:@"fieldRole"];
    
    //    NSString *fieldId;
    //    if([dic valueForKey:@"relationTableId"]!=nil){
    //        if([dic objectForKey:@"dialogField"]){
    //
    //            fieldId= [dic objectForKey:@"dialogField"];
    //        }else{
    //            fieldId= [dic objectForKey:@"fieldId"];
    //        }
    //    }else{
    //        fieldId= [dic objectForKey:@"fieldId"];
    //
    //    }
    //    NSString *usageFieldId = [dic objectForKey:@"fieldId"];
    //    if ([[NSString stringWithFormat:@"%@", [dic valueForKey:@"fieldId"]]isEqualToString:@"630"]) {
    //
    //    }
    //    NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
    
#warning maybe difernt tableId to use it for a moment
    //    NSString *tableId= [_buttonDic objectForKey:@"tableId"];
    //    NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
    
    NSString *baseString = [_keyValueClass makeTheBaseString:model andTheEditDic:_buttonDic]; // makeTheBaseString
    
    //    NSString *relationTableId=[NSString stringWithFormat:@"%@",[dic objectForKey:@"relationTableId"]] ;
    //    NSString *showFieldArr=[NSString stringWithFormat:@"%@",[dic objectForKey:@"showFieldArr"]] ;
    //    NSString *showFieldArr=[NSString stringWithFormat:@"%@",[dic objectForKey:@"fieldId"]] ;
    
    //    NSString *dialogField=[NSString stringWithFormat:@"%@",[dic objectForKey:@"dialogField"]] ;
    
    //    NSString *fieldOfNum;
    //    if(usageFieldId){
    
    //        fieldOfNum=[NSString stringWithFormat:@"%@_au_%@_%@_%@_dz", _tString,relationTableId,showFieldArr,usageFieldId];
    //    }else{
    //        fieldOfNum=[NSString stringWithFormat:@"%@_au_%@_%@_%@_dz", _tString,relationTableId,showFieldArr,fieldId];
    //    }
    //    NSString *fieldOfValue =[NSString stringWithFormat:@"t%i_au_%@_%@_%@", _tNum+1,relationTableId,showFieldArr,fieldId];
    
    //    NSInteger num =[fieldRole integerValue];
    //
    //    if(num == 22||num == 20){
    //
    //        [_sendMutDic setObject:numStr forKey:[self getAlertKKey:dic]];
    //        //      NSLog(@"%@",_sendMutDic);
    //    }else if(num == 21){
    //
    //        NSInteger arrNUm = [arr[0] count];
    //        for(int i=0;i<arrNUm;i++){
    //            NSMutableDictionary *ddd = [[NSMutableDictionary alloc]init];
    //            [ddd setObject:[arr[1]objectAtIndex:i] forKey:[self getAlertMoreKKeyFieldOfValue:dic]];
    //            [_mangManArr addObject:ddd];
    //        }
    //        NSMutableDictionary *dad = [[NSMutableDictionary alloc]init];
    //        [dad setObject:[NSString stringWithFormat:@"%ld",(long)arrNUm] forKey:[self getAlertMoreKKeyFieldOfNum:dic]];
    //        [_mangManArr addObject:dad];
    //        NSLog(@"%@", _mangManArr);
    //    }
    
    [self whileHaveTmpFieldId:model andBaseString:[KeyNameClass getKeyName:model.fieldRole andBaseString:baseString andTUseString:self.tString]andValue:model.true_defaultShowValId];
}

#pragma mark - reWrite function of fa class
-(void)createLeftNavBar{
    UIButton *leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftNavBtn.frame = CGRectMake(0, 0, 50, 37/2);
    //    [leftNavBtn setBackgroundImage:[UIImage imageNamed:@"形状1-19-拷贝-4"] forState:UIControlStateNormal];
    [leftNavBtn setTitle:@"取消" forState:UIControlStateNormal];
    [leftNavBtn addTarget:self action:@selector(LeftClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:leftNavBtn];
    self.navigationItem.leftBarButtonItem = item;
    
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (alertView == _alertSure) {
        if(buttonIndex==1){
            
            [self addRequest];
        }
        else{
            _alertSure.hidden = YES;
        }
        
        self.subBtn.enabled = YES;
        return;
    }
    NSLog(@"%ld",(long)buttonIndex);
    if(buttonIndex==0&&alertView==_alert){
        [self.navigationController popViewControllerAnimated:YES];
    }
    else if(alertView==_alert){
        _alert.hidden = YES;
    }
    
}

-(void)createRightNavBar{
    
    UIButton *rightNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightNavBtn.frame = CGRectMake(0, 0, 50, 23);
    [rightNavBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    [rightNavBtn setBackgroundImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateNormal];
    [rightNavBtn addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:rightNavBtn];
    //    self.navigationItem.leftBarButtonItem = item;
    [rightNavBtn setTitle:@"提交" forState:UIControlStateNormal];
    self.subBtn = rightNavBtn;
    
    self.subBtn.hidden = YES;
    
    self.navigationItem.rightBarButtonItem = item;
    
}

-(void)rightClick:(UIButton *)btn{
    btn.enabled = NO;
    if(![focusTextField.text isEqualToString:@""]){
//        NSDictionary *dic= [_filedArr objectAtIndex:focusTextField.indexPath.row];
        
        EditModel *model= [_filedArr objectAtIndex:focusTextField.indexPath.row];

        NSString *fieldRole=[NSString stringWithFormat:@"%@", model.fieldRole];
        
        //    NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
        NSString *role =[NSString stringWithFormat:@"%@",fieldRole];
        BOOL is = [NSString witchRoleis:role withStr:focusTextField.text];
        if(is){
            NSLog(@"%@",_sendMutDic);
        }
        else{
            UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil message:@"请输入正确的格式" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
            [alert show];
            focusTextField.text  =@"";
            btn.enabled = YES;
            
            return;
        }
    }
    NSString *string = @"isok";
    
    for(CustomTextField *field in _textFieldArr){
        if([field.text isEqualToString:@""]){
            
            string = @"notok";
            
        }
    }
    
    if(focusTextField)[focusTextField resignFirstResponder];
    
    NSString *Tips;//提示
    NSString *requiredItem;//必填项
    NSString *requiredItemCellText;//必填项cell的提示语
    NSString *cancel;
    NSString *isOKStr;
    NSString *tipString;
    //这里添加功能判断
    if (getEnglishLanguage()) {
        Tips = @"Tips";
        requiredItem = @"Required Item";
        requiredItemCellText = @"You must fill in the required item";
        cancel = @"Cancel";
        isOKStr = @"OK";
//        if (_toString.length>0&&_toString!=nil) {
        
//            tipString = [NSString stringWithFormat:@"Are your sure to %@", _toString];
//        }else{
            
            tipString = [NSString stringWithFormat:@"Are your sure to add"];
            
//        }
    }else{
        Tips = @"提示";
        requiredItem = @"必填";
        requiredItemCellText = @"必填项不能为空";
        cancel = @"取消";
        isOKStr = @"确定";
//        if (_toString.length>0&&_toString!=nil) {
        
//            tipString = [NSString stringWithFormat:@"是否%@", _toString];
//        }else{
            
            tipString = [NSString stringWithFormat:@"是否添加"];
            
//        }
    }
    
    
    
    
    
    
    if([string isEqualToString:@"isok"]){
        _alertSure =[[UIAlertView alloc]initWithTitle:Tips message:tipString delegate:self cancelButtonTitle:cancel otherButtonTitles:isOKStr, nil];
        [_alertSure show];
    }
    else{
        _alertSure =[[UIAlertView alloc]initWithTitle:Tips message:requiredItemCellText delegate:self cancelButtonTitle:isOKStr otherButtonTitles:nil, nil];
        [_alertSure show];
        
        
    }

    
    
//    if([string isEqualToString:@"isok"]){
//        _alertSure =[[UIAlertView alloc]initWithTitle:@"提示" message:@"是否添加" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//        [_alertSure show];
//    }
//    else{
//        _alertSure =[[UIAlertView alloc]initWithTitle:@"提示" message:@"必填项不能为空" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
//        [_alertSure show];
//    }
    //    _alertSure =[[UIAlertView alloc]initWithTitle:@"提示" message:@"是否添加" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    //    [_alertSure show];
    
}


#pragma mark - ADDReq
-(void)addRequest{
    //    _sendMutDic = [[NSMutableDictionary alloc]init];
    EditModel *model;
    if(focusTextField){
        
        model = [_filedArr objectAtIndex:focusTextField.indexPath.row];
    }
    
    NSString *fieldRole=[NSString stringWithFormat:@"%@", model.fieldRole]; // [dic objectForKey:@"fieldRole"]
    
    if(focusTextField&&![fieldRole isEqualToString:@"21"]&&![fieldRole isEqualToString:@"20"]&&![fieldRole isEqualToString:@"22"]){
        if([[NSString stringWithFormat:@"%@", model.fieldRole] isEqualToString:@"16"]){  // fieldRole
            
        }
        else{
            [_sendMutDic setObject:focusTextField.text forKey:model.montageName]; // [KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]
            model.true_defaultShowValName = focusTextField.text;
            //*** receive show
            //            [_selectedDic setObject:focusTextField.text forKey:[NSString stringWithFormat:@"%ld", (long)focusTextField.indexPath.row]];
            
        }
    }
    
    
    NSMutableDictionary *dicSendBack = [[NSMutableDictionary alloc]init];
    [dicSendBack setValue:_sendMutDic forKey:@"sendD"];
    [dicSendBack setValue:_mangManArr forKey:@"mangManD"];
    [dicSendBack setObject:_selectedDic forKey:@"selectedDic"];
    if(self.delegateView){
        
        [self.delegateView performSelector:@selector(receiveAddDataList:) withObject:dicSendBack];
  
    }
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


-(void) performDismiss:(NSTimer *)timer
{
    [_alert dismissWithClickedButtonIndex:0 animated:NO];
    
    if(addSucceed)[self.navigationController popViewControllerAnimated:YES];
}
-(void)dataRequest{
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:userName() forKey:@"loginName"];
    [parmas setObject:passWord() forKey:@"password"];
    
    NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
    [parmas setObject:strTnum forKey:@"tNumber"];

//    NSString *path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
//    
//    NSString *path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listForAdd%@%@.plist", self.tableId, self.pageId]];
    
//    NSDictionary *saveDic = [[NSDictionary alloc]initWithContentsOfFile:path3];
    
//    NSLog(@"%@",_addDic);
//    //    [parmas setObject:[_buttonDic objectForKey:@"startTurnPage"] forKey:@"pageId"];
//    //    [parmas setObject:self.tableId forKey:@"tableId"];
//    if([self.buttonDic valueForKey:@"startTurnPage"])[parmas setObject:[self.buttonDic valueForKey:@"startTurnPage"] forKey:@"pageId"];
//    [parmas setObject:self.tableId forKey:@"tableId"];
//    if([saveDic valueForKey:@"alterTime"])
//    {
//        [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
//    }else{
//        [parmas setObject:@"" forKey:@"alterTime"];
//    }
    
    //    [parmas setObject:@"" forKey:@"alterTime"];
    
    //    NSString *url = [_addDic objectForKey:@"buttonTurnUrl"];http://192.168.6.150:8081/edus_auto/add_toAddPage.do?tableId=16&pageId=19http://192.168.6.150:8081/edus_auto/add_interfaceToAdd.do?password=000000&alterTime=&source=1&pageId=19&loginName=admin&tableId=16
    //    saveURL(url, ADD_URL);
    //    NSString *requestStr = getUrl(ADD_URL);
    
    
    
    
//    NSString *requestStr;
//    //    pageId=240&tableId=70&mainId=75&mainTableId=19&mainPageId=152
//    if(![[NSString stringWithFormat:@"%@", [self.buttonDic valueForKey:@"buttonType"]]isEqualToString:@"18"]){
//        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, ADDMF_URL];
//        
//        
//    }else{
//        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, RELATIONADD_URL];
//        [parmas setObject:[_buttonDic objectForKey:@"startTurnPage"] forKey:@"pageId"];
//        [parmas setObject:[_buttonDic valueForKey:@"tableId"] forKey:@"tableId"];
//        
//        [parmas setObject:self.tableId forKey:@"mainTableId"];
//        [parmas setObject:self.pageId forKey:@"mainPageId"];
//        
//        [parmas setObject:[NSString stringWithFormat:@"%@", [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]] forKey:@"mainId"];
//        
//        
//        //pageId=240&tableId=70&mainId=103&mainTableId=19&mainPageId=152
//    }
    
    [parmas setObject:self.tableId forKey:@"tableId"];
    [parmas setObject:self.pageId forKey:@"pageId"];
    
    NSString *requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, ADDMF_URL];
    
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        if(data!=nil&&!error){
            
            self.subBtn.hidden = NO;
            
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            // 数据处理，当没问题的情况下
            [self dataUse:obj];
            //            _itemDic = [obj valueForKey:@"dataInfo"];
            //            [self.tbView reloadData];
        }else{
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            
        }
        
        [self.tbView reloadData];

//        if(data!=nil&&!error){
//            self.subBtn.hidden = NO;
//            
//            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//            
//            
//            NSString *strForarrR = [NSString stringWithFormat:@"%@_%@_glAddSql_%@", self.tableId, [_buttonDic objectForKey:@"startTurnPage"], [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]];
//            
//            if([obj valueForKey:@"alterTime"]!=nil){
//                if ([[NSString stringWithFormat:@"%@", [obj valueForKey:@"error"]] isEqualToString:@"1"]) {
//                    [self showLabelWithText:[obj valueForKey:@"errorInfo"]];
//                }
//                NSLog(@"%@",obj);
//                if([obj objectForKey:@"pageSet"])_filedArr = [NSArray arrayWithArray:[[obj objectForKey:@"pageSet"] valueForKey:@"fieldSet"]];
//                
//                
//                
//                if([obj objectForKey:@"dataInfo"])_defaultArr = [NSMutableArray arrayWithArray:[[obj objectForKey:@"dataInfo"] valueForKey:strForarrR]];
//                
//                if([obj objectForKey:@"pageSet"]){
//                    
//                    self.relationId = [NSString stringWithFormat:@"%@", [[obj objectForKey:@"pageSet"] valueForKey:@"relationFieldId"]];
//                }
//            }else{
////                if([saveDic objectForKey:@"pageSet"])_filedArr = [NSArray arrayWithArray:[[saveDic objectForKey:@"pageSet"] valueForKey:@"fieldSet"]];
////                
////                if([saveDic objectForKey:@"dataInfo"])_defaultArr = [NSMutableArray arrayWithArray:[[saveDic objectForKey:@"dataInfo"] valueForKey:strForarrR]];
////                if([saveDic valueForKey:@"relationFieldInfo"]){
////                    self.relationId = [NSString stringWithFormat:@"%@", [[saveDic objectForKey:@"pageSet"] valueForKey:@"relationFieldId"]];
////                }
//                
//                
//            }
//            
//            //*** 需要其他生成
//            _needElseChange = [[NSMutableArray alloc]init];
//            
//            for (NSDictionary *dicDataNeedElse in _filedArr) {
//                if ([dicDataNeedElse valueForKey:@"tmpFieldId"]) {
//                    [_needElseChange addObject:dicDataNeedElse];
//                }
//            }
//            [self.tbView reloadData];
//            
//        }else{
//            
//            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
//            [self showLabelWithText:str];
//            
//            self.subBtn.hidden = YES;
//        }
        
    }];
}
#pragma mark - 数据处理
-(void)dataUse:(id)obj{
    
    //***jsonModel 数据处理 , 如果键值对有所改变 ， 那么就将 model 内的 内容进行更改，注意 使用时的问题 ， cellForrowInThePath
    //    _conditionShow = [[NSMutableArray alloc]init];
    
    if([obj objectForKey:@"pageSet"]){
        
        self.relationId = [NSString stringWithFormat:@"%@", [[obj objectForKey:@"pageSet"] valueForKey:@"relationFieldId"]]; // 将关联添加的 relationId 取出来 ， 如果要是关联添加的话，就可以直接使用关联添加的Id

        NSArray *dataArr = [[obj objectForKey:@"pageSet"]valueForKey:@"fieldSet"];
        for (NSDictionary *dic in dataArr) {
            EditModel *model = [[EditModel alloc]init];
            model = [model initWithDictionary:dic error:nil];
            [_filedArr addObject:model];
            if (model.jsWhereStr) { // 查看是否有启用禁用条件
                [_conditionShow addObject:model];
            }
            if (model.tmpFieldId) {
                [_needElseChange addObject:model];
            }
            
            
            
            
            NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole];
            NSInteger num =[fieldRole integerValue];
            // 拼接上传值
            if(num == 20 || num == 21 || num == 22){// 弹层 下拉树 内部对象
                
                //                [self whileFieldRowTypeIsspeciall:model];
                
                [_keyValueClass whileFieldRowTypeIsspeciall:model andTnum:_tNum andTstring:_tString andSendMutDic:_sendMutDic andManyMan:_mangManArr andEditDetailDic:_buttonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, NSDictionary *dicDEdit, EditModel *model){
                    _sendMutDic = send;
                    _mangManArr = manyman;
                    _buttonDic = dicDEdit;
                }];
            }else if(num == 14||num==28||num==26|| num == 15){ // 时间格式的 使用
                
                if(model.true_defaultShowValName){
                    model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                    [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                    
                }else{
                    [_sendMutDic setObject:@"" forKey:model.montageName];
                }
                
                
            }else if(num!=-1){
                if(model.true_defaultShowValName){
                    [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                }else{
                    [_sendMutDic setObject:@"" forKey:model.montageName];
                }
                
            }
            
        }
        NSArray *arrHiddenText = [[obj objectForKey:@"pageSet"]valueForKey:@"hideFieldSet"];
        
        for (NSDictionary *dic in arrHiddenText) {
            EditModel *model = [[EditModel alloc]init];
            model = [model initWithDictionary:dic error:nil];
            [_hiddenArr addObject:model];
        }
        
        [self.tbView reloadData];
    }
}

-(void)createUI{
    self.tbView = [[UITableView alloc]init];
    [self.view addSubview:self.tbView];
    self.tbView.delegate = self;
    self.tbView.dataSource = self;
    self.tbView.separatorStyle =UITableViewCellSeparatorStyleNone;
    [self.tbView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    
    
    withShowPicView = [[UIView alloc]init];
    withShowPicView.hidden = YES;
    [self.view addSubview:withShowPicView];
    withShowPicView.backgroundColor = [UIColor whiteColor];
    [withShowPicView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(-49);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@(342/2));
    }];
    
    _timeBackImg = [[UIImageView alloc]init];
    [self.view addSubview:_timeBackImg];
    [_timeBackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
        make.bottom.equalTo(withShowPicView.mas_top);
    }];
    _timeBackImg.alpha = 0.5;
    _timeBackImg.userInteractionEnabled = YES;
    _timeBackImg.backgroundColor = [UIColor blackColor];
    _timeBackImg.hidden = withShowPicView.hidden;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cancelClick)];
    [_timeBackImg addGestureRecognizer:tap];
    
    
    UIImageView *whichView = [[UIImageView alloc]init];
    whichView.image = [UIImage imageNamed:@"whitchB"];
    whichView.userInteractionEnabled = YES;
    [withShowPicView addSubview:whichView];
    [whichView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(withShowPicView.mas_top);
        make.left.equalTo(withShowPicView.mas_left);
        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(100/2));
    }];
    UIButton *cancelButton = [[UIButton alloc]init];
    //    cancelButton.backgroundColor = [UIColor blackColor];
    [whichView addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(whichView.mas_centerY);
        make.left.equalTo(whichView.mas_left).offset(32/2);
        //        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(48/2));
    }];
    [cancelButton setImage:[UIImage imageNamed:@"cancelNbUTTON"] forState:UIControlStateNormal];
    [cancelButton setImage:[UIImage imageNamed:@"cancelButton"] forState:UIControlStateSelected];
    UILabel *centerLabel = [[UILabel alloc]init];
    [whichView addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cancelButton.mas_centerY);
        make.centerX.equalTo(whichView.mas_centerX);
        //        make.right.equalTo(withShowPicView.mas_right);
        //        make.height.equalTo(@(48/2));
    }];
    
    
    centerLabel.font = [UIFont systemFontOfSize:32/2];
    centerLabel.text = @"选择时间";
    centerLabel.textColor = [UIColor colorWithRed:0x74/255.0 green:0x75/255.0 blue:0x79/255.0 alpha:1];
    UIButton *okButton = [[UIButton alloc]init];
    [whichView addSubview:okButton];
    [okButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cancelButton.mas_centerY);
        make.right.equalTo(whichView.mas_right).offset(-32/2);
        //        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(48/2));
    }];
    [cancelButton addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
    [okButton addTarget:self action:@selector(okClick) forControlEvents:UIControlEventTouchUpInside];
    [okButton setImage:[UIImage imageNamed:@"okNButton"] forState:UIControlStateNormal];
    [okButton setImage:[UIImage imageNamed:@"okButotn"] forState:UIControlStateSelected];
    //    whichView.backgroundColor = [UIColor grayColor];
    //    cancelButton.backgroundColor = [UIColor blackColor];
    //    okButton.backgroundColor = [UIColor orangeColor];
    
    _pickerView = [[UIPickerView alloc]init];
    _pickerView.backgroundColor = [UIColor whiteColor];
    _pickerView.delegate = self;
    _pickerView.dataSource = self;
    _pickerView.showsSelectionIndicator = YES;
    
    _pickerView.hidden = YES;
    [withShowPicView addSubview:_pickerView];
    [_pickerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(withShowPicView.mas_centerX);
        make.bottom.equalTo(withShowPicView.mas_bottom);
        make.top.equalTo(whichView.mas_bottom).offset(50);
        make.width.equalTo(withShowPicView.mas_width);
    }];
    
    
    _oneSelectView = [[OneSelectView alloc]initWithFrame:CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200)];
    [self.view addSubview:_oneSelectView];
    ;
    _oneSelectView.delegateView = self;
    
    
    _SelectManyView =[[SelectManyView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2-150, 40, 300, 300)];
    [self.view addSubview:_SelectManyView];
    ;
    _SelectManyView.delegateView = self;
    _SelectManyView.hidden = YES;
    
    
    self.pickerTime = [[PickerTimeView alloc]init];
    
    self.pickerTime.delegagte = self;
    [self.view addSubview:self.pickerTime];
    [self.pickerTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(self.view.mas_top);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    self.pickerTime.hidden = YES;
}

#pragma mark - dateReceiveData
-(void)picTimeReceive:(NSString *)dateStr{
    NSLog(@"%@", dateStr);
    
    EditModel *model = _filedArr[_rowNum];
    
    CustomTextField *titleText = (CustomTextField *)[self.view viewWithTag:1000+_rowNum];
    titleText.hidden = NO;
    NSString *str =[NSString stringWithFormat:@"%@", dateStr];
    titleText.text = str;
    
    model.true_defaultShowValName = str;
    
    //    [_textDic setObject:str forKey:[NSString stringWithFormat:@"%ld",(long)_rowsNum]];
    //    NSString *fieldRole= model.fieldRole; //[dic objectForKey:@"fieldRole"];
    //    NSString *fieldId= model.fieldId; //[dic objectForKey:@"fieldId"];
    //    NSString *pageId= [_EditDic objectForKey:@"startTurnPage"];
    ////    //        NSString *tableId= [_dataDic objectForKey:@"tableId"];
    //    NSString *tableId= [_EditDic objectForKey:@"tableId"];
    
    //    NSString *baseText = [KeyNameClass getKeyName:fieldRole andBaseString:[NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId] andTUseString:_tString]; //[NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
    NSString *baseString = [NSString stringWithFormat:@"%@", model.montageName]; //[NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
    [_sendMutDic setObject:str forKey:baseString];
    NSLog(@"%@",_sendMutDic);
    
    self.pickerTime.hidden = YES;
    
    //    focusTextField.text = [NSString stringWithFormat:@"%@", dateStr];
    //            yeaStr = nil;
    //            montStr = nil;
    //            daStr = nil;
    
    
    //    NSDictionary *dic= [_filedArr objectAtIndex:focusTextField.indexPath.row];
    //    NSString *fieldRole= [dic objectForKey:@"fieldRole"];
    //    NSString *fieldId= [dic objectForKey:@"fieldId"];
    //    NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
    //
    //#warning tableId
    //    NSString *tableId= [_buttonDic objectForKey:@"tableId"];
    //    NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
    //    if(focusTextField!=nil){
    //
    //        [_sendMutDic setObject:focusTextField.text forKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]];
    //
    //        //*** receive show
    //        [_selectedDic setObject:focusTextField.text forKey:[NSString stringWithFormat:@"%ld", (long)focusTextField.indexPath.row]];
    //
    //    }
    //        self.pickerTime.hidden = YES;
    
    
}
#pragma mark - oneSelectBtn founction
-(void)leftBtnClick:(UIButton *)btn{
    
    _oneSelectView.hidden = YES;
    _oneSelectView.frame = CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200);
    _backImg.hidden = YES;
    
    _SelectManyView.hidden = YES;
    _SelectManyView.frame = CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200);
    _backImg.hidden = YES;
    
}

#pragma mark - oneselectViewReturn Data
-(void)rightBtnClick:(UIButton *)btn{
    
    [self setNormalDataDic];
}
#pragma mark - 正常字段设置数据字典
-(void)setNormalDataDic{
    if(_oneSelectView.seleTitle !=nil){
        CustomTextField *textField = (CustomTextField *)[self.view viewWithTag:1000+_indexNum];
        textField.text = _oneSelectView.seleTitle;
        _oneSelectView.frame = CGRectMake(50, 1000, 200, 200);
        
        EditModel *model= [_filedArr objectAtIndex:textField.indexPath.row];
        
        
#warning ttableId may not this
        [_sendMutDic setObject:_oneSelectView.seleTitleNum forKey:model.montageName];
        model.true_defaultShowValName = _oneSelectView.seleTitleNum;
        
        //*** receive show
        //        [_selectedDic setObject:_oneSelectView.seleTitle forKey:[NSString stringWithFormat:@"%ld", (long)focusTextField.indexPath.row]];
        _oneSelectView.seleTitle = @"";
        
        NSLog(@"%@",_sendMutDic);
        
        for (EditModel *model in _conditionShow) {
            //            BOOL is = [self textQianTiTiaoJian:model];
            
            NSString *isN = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_filedArr];
            
            if (![isN isEqualToString:@"YES"]) {
                
                [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", isN]];
                
                return;
            }
            
            BOOL is;
            
            if ([isN isEqualToString:@"YES"]) {
                is = YES;
            }else{
                is = NO;
            }

            
            if (!is) {
                //                [self removeAlready:model];
                
                [_keyValueClass removeAlready:model andTstring:_tString andManyManyArr:_mangManArr andTnumBer:_tNum andSendMutDic:_sendMutDic andEditDic:_buttonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, EditModel *model) {
                    _sendMutDic = send;
                    _mangManArr = manyman;
                    
                }];
                model.true_defaultShowValName = @"";
                model.true_defaultShowValId = @"";
            }
        }
        
        [self.tbView reloadData];
        
    }
    _oneSelectView.hidden=YES;
    _backImg.hidden = YES;
    
}

#pragma many ele
-(void)rightBtnClick1:(UIButton *)btn{
    if(_SelectManyView.seleTitle !=nil){
        CustomTextField *textField = (CustomTextField *)[self.view viewWithTag:1000+_indexNum];
        textField.text = _SelectManyView.seleTitle;
        _SelectManyView.frame = CGRectMake(50, 1000, 200, 200);
        //    _oneSelectView=nil;
        //    _oneSelectView = [[OneSelectView alloc]initWithFrame:CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200)];
        //        [self.view addSubview:_SelectManyView];
        NSDictionary *dic= [_filedArr objectAtIndex:textField.indexPath.row];
        NSString *fieldRole= [dic objectForKey:@"fieldRole"];
        NSString *fieldId= [dic objectForKey:@"fieldId"];
        NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
        
#warning ttableId may not this
        NSString *tableId= [_buttonDic objectForKey:@"tableId"];
        NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
        [_sendMutDic setObject:_SelectManyView.seleTitleNum forKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]];
        
        //*** receive show
        [_selectedDic setObject:_SelectManyView.seleTitle forKey:[NSString stringWithFormat:@"%ld", (long)focusTextField.indexPath.row]];
        
        _oneSelectView.seleTitle = @"";
        
        NSLog(@"%@",_sendMutDic);
    }
    _SelectManyView.hidden=YES;
    _backImg.hidden = YES;
    
}


-(void)sexBtn:(MyButton2 *)btn{
    sexBtn = btn;
}

#pragma mark - show pickerView and the cancel btn and the sure btn
-(void)cancelClick{
    withShowPicView.hidden = YES;
    _timeBackImg.hidden = withShowPicView.hidden;
    
}

-(void)okClick{
    
    /**
     yeaStr, montStr, daStr 即为年月日
     */
    if (yeaStr&&montStr&&daStr) {
        _pickerView.hidden = YES;
        withShowPicView.hidden = YES;
        _timeBackImg.hidden = withShowPicView.hidden;
        
        focusTextField.text = [NSString stringWithFormat:@"%@-%@-%@", yeaStr, montStr, daStr];
        //            yeaStr = nil;
        //            montStr = nil;
        //            daStr = nil;
        
        
        NSDictionary *dic= [_filedArr objectAtIndex:focusTextField.indexPath.row];
        NSString *fieldRole= [dic objectForKey:@"fieldRole"];
        NSString *fieldId= [dic objectForKey:@"fieldId"];
        //NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
        
#warning tableId may not this
        //NSString *tableId= [_buttonDic objectForKey:@"tableId"];
        NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",_tableId,_pageId,fieldId];
        if(focusTextField!=nil) {
            
            [_sendMutDic setObject:focusTextField.text forKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]];
            //*** receive show
            [_selectedDic setObject:focusTextField.text forKey:[NSString stringWithFormat:@"%ld", (long)focusTextField.indexPath.row]];
            
        }
        
    }
}

#pragma mark - UITableViewCellDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _filedArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    EditModel *model = _filedArr[indexPath.row];
    
    //    NSArray *allkey = [_textDic allKeys];
    
    
    //NSInteger roleNum = [model.fieldRole integerValue];
    NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole];
    
#pragma - mark   *处理cell不同样式
    NSInteger num =[fieldRole integerValue];
    
    static NSString *listCell = @"listCell";
    ListDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:listCell];
    if (cell == nil) {
        cell = [[ListDetailCell alloc]initWithReuseIdentifier:listCell];
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell setEditIs:YES];
    //    NSDictionary *dic = [_filedArr objectAtIndex:indexPath.row];
    NSString *indexString = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
    model.indexPath  = indexString;
    //    [dic setValue:indexString forKey:@"indexPath"];
    
    cell.title.text = model.fieldCnName; //[dic objectForKey:@"fieldCnName"];
    cell.titleText.delegate = self;
    NSString *mustStr = [NSString stringWithFormat:@"%@",model.ifMust];
    if( [mustStr isEqualToString:@"1"]){
        //这里添加功能判断
        if (getEnglishLanguage()) {
            cell.titleText.placeholder = @"Required Item";
        }else{
            cell.titleText.placeholder = @"必填";
        }

        cell.titleText.type = @"ismust";
        [_textFieldArr addObject:cell.titleText];
    }
    
    cell.titleText.indexPath = indexPath;
    cell.titleText.tag = 1000+indexPath.row;
    cell.titleText.delegate = self;
    //    NSString *fieldRole =[dic objectForKey:@"fieldRole"];
    //    NSInteger num =[fieldRole integerValue];
    
    
    //*** 可点 不可点          的跳转页面
    cell.titleText.tag = 1000+indexPath.row;
    if (num ==16||num == 14||num==28||num==26||num == 15||model.fieldAliasName||model.tmpFieldId||num==20||num==21||num==22) { // 15 时间 14 日期15 数据字典
        
        if (model.tmpFieldId) {
            for (EditModel *need in _needElseChange) {
                need.indexPathRow = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
                
            }
        }

        cell.titleText.editable = NO;
        
        if (model.tmpFieldId) {
            for (EditModel *need in _needElseChange) {
                need.indexPathRow = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
                
            }
        }
    }else{
        cell.titleText.editable = YES;
    }
    
    //*** 左侧显示Label
    cell.title.text =[NSString stringWithFormat:@"%@:",model.fieldCnName];
    
    //    cell.title.text =[NSString stringWithFormat:@"%@:",[dic objectForKey:@"fieldCnName"]];
    
    cell.titleText.indexPath = indexPath;
    
    //*** right textFileld text
    NSString *cellTitleTextStringText;
    if(model.true_defaultShowValName&&num!=16&&num!=14&&num!=15&&num!=26&&num!=28){
        
        cellTitleTextStringText= [NSString stringWithFormat:@"%@", model.true_defaultShowValName];
    }else if(num == 16){
        NSArray *dataDicArr = [NSArray arrayWithArray:model.dicList]; // 取出数据字典中的值
        NSString *inter = [NSString stringWithFormat:@"%@", model.true_defaultShowValName]; // 默认值
        
        for (NSDictionary *dicDicList in dataDicArr) {
            {
                NSString *inter1 = [NSString stringWithFormat:@"%@", [dicDicList valueForKey:@"DIC_ID"]]; // 数据字典内值
                if([inter isEqualToString:inter1]){
                    cellTitleTextStringText = [NSString stringWithFormat:@"%@", [dicDicList valueForKey:@"DIC_NAME"]];
                }
            }
        }
        
    }else if(model.true_defaultShowValName&&(num==14||num==15||num==16||num==26||num==28)){
        
        cellTitleTextStringText = model.true_defaultShowValName; //[KeyValuesClass dateGlinToFormate:model.true_defaultShowValName]; // 由于时间格式返回的都是  格林尼治 所以 ····
    }else{
        cellTitleTextStringText = @"";
    }
    
    
    
    cell.titleText.text = cellTitleTextStringText;
    
    
    
    //*** 是否可更改 ， 也就是说回显
    
    if([[NSString stringWithFormat:@"%@", model.ifUpdate] isEqualToString:@"0"]||model.ifUpdate==nil){
        cell.backgroundColor = [UIColor colorWithRed:241/255.0 green:241/255.0 blue:241/255.0 alpha:1];
        cell.titleText.editable = NO;
    }else{
        cell.backgroundColor = [UIColor whiteColor];
    }

    
    
    
    
    
    return cell;
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ListDetailCell *cell = (ListDetailCell *)[tableView cellForRowAtIndexPath:indexPath];
    if(focusTextField)[focusTextField resignFirstResponder];
    
    focusTextField = cell.titleText;
    NSLog(@"~~~~%@",cell.titleText.type);
    
    //    NSDictionary *dic= [_filedArr objectAtIndex:indexPath.row];
    
    EditModel *model = _filedArr[indexPath.row];
    NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole]; //[dic objectForKey:@"fieldRole"];
    NSInteger addStyle = [[NSString stringWithFormat:@"%@", model.addStyle] integerValue];
    
    //*** 前提条件
    if(model.jsWhereStr){ // [dic valueForKey:@"jsWhereStr"]
        
        //        BOOL is = [self textQianTiTiaoJian:dic];
        
        NSString *isN = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_filedArr];
        
        if (![isN isEqualToString:@"YES"]) {
            
            [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", isN]];
            
            return;
        }
        
        BOOL is;
        
        if ([isN isEqualToString:@"YES"]) {
            is = YES;
        }else{
            is = NO;
        }

        
        if (!is) {
            return;
        }
    }
    NSInteger num =[fieldRole integerValue];
    
    
    
    if (model.tmpFieldId||model.fieldAliasName) { // 被其他的的的额大大神蛋白生成或默认 - 显示 - 的东西 return
        return;
    }
    
    //    if ([dic valueForKey:@"tmpFieldId"]||[dic valueForKey:@"fieldAliasName"]) {
    //        return;
    //    }
    
    /**
     不同状况调不同方法
     */
    if(num == SEX){
        //        sexView.hidden = NO;
        [UIView animateWithDuration:0.5 animations:^{
            //            _oneSelectView = [[OneSelectView alloc]initWithFrame:CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width-100, 500)];
            _oneSelectView.frame = CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width-100, 200);
        }];
        //        NSString *dicstr = [dic objectForKey:@"dicOptions"];
        //        NSData *dicData = [dicstr dataUsingEncoding:NSUTF8StringEncoding];
        NSString *strDicChildShow = [NSString stringWithFormat:@"%@", model.dicChildShow];
        
        //        NSString *strDicChildShow = [NSString stringWithFormat:@"%@", [dic valueForKey:@"dicChildShow"]];
        NSArray *chilArr = [strDicChildShow componentsSeparatedByString:@","];
        NSArray *dicLArr = model.dicList; //[dic valueForKey:@"dicList"];
        NSMutableArray *dicArr = [[NSMutableArray alloc]init];// = [dic valueForKey:@"dicList"];
        if(strDicChildShow.length>0){
            for (NSDictionary *dicElement in dicLArr) {
                NSString *strEleDic = [NSString stringWithFormat:@"%@", [dicElement valueForKey:@"DIC_ID"]];
                
                for (id obj in chilArr) {
                    NSString *objStr = [NSString stringWithFormat:@"%@", obj];
                    if ([strEleDic isEqualToString:objStr]) {
                        [dicArr addObject:dicElement];
                    }
                }
            }
        }else{
            [dicArr addObjectsFromArray:dicLArr];
        }
        
#warning 可能要改
        _oneSelectView.dataArr = dicArr;
        withShowPicView.hidden = YES;
        _timeBackImg.hidden = withShowPicView.hidden;
        
        _pickerView.hidden = YES;
        _indexNum = indexPath.row;
        _oneSelectView.hidden = NO;
        
        if (focusTextField) {
            [focusTextField resignFirstResponder];
        }
        [self.view bringSubviewToFront:_oneSelectView];
        _backImg.hidden = NO;
        
    } else if (num == 17){//多选
        [self.view bringSubviewToFront:_backImg];
        _backImg.hidden = NO;
        [self.view bringSubviewToFront:_SelectManyView];
        [UIView animateWithDuration:0.5 animations:^{
            //            _oneSelectView = [[OneSelectView alloc]initWithFrame:CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width-100, 500)];
            _SelectManyView.frame = CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width-100, 200);
        }];
        _indexNum = indexPath.row;
        NSString *dicstr = [NSString stringWithFormat:@"%@", model.dicOptions]; //[dic objectForKey:@"dicOptions"];
        NSData *dicData = [dicstr dataUsingEncoding:NSUTF8StringEncoding];
        NSArray *dicArr = [NSJSONSerialization JSONObjectWithData:dicData options:0 error:nil];
        _pickerView.hidden = YES;
        _SelectManyView.dataArr = dicArr;
        _SelectManyView.hidden = NO;
        
        //        if () {
        //            <#statements#>
        //        }
    }else if(num == 14||num==28||num==26){
        self.pickerTime.dataFormate = model.dateType;
        self.pickerTime.hidden = NO;
        self.pickerTime.datePicer.datePickerMode = UIDatePickerModeDate;
    }else if(num == 15){ // 时间
        self.pickerTime.dataFormate = model.dateType;
        self.pickerTime.hidden = NO;
        self.pickerTime.datePicer.datePickerMode = UIDatePickerModeTime;
    }
    else if(num == 20||num == 21||num == 22){ //*** 下拉树  + 弹层
        
        if (addStyle == 3) { // 点击加号添加
            if (model.showFieldArr) { // pageId [dic valueForKey:@"showFieldArr"]
                
                PicAddListsViewController *picAddVC = [[PicAddListsViewController alloc]init];
                
                //*** 传送已添加的值
                if ([_addStyleEqualto3 valueForKey:[NSString stringWithFormat:@"%i", indexPath.row]]) {
                    picAddVC.defaultSourceArr = [_addStyleEqualto3 valueForKey:[NSString stringWithFormat:@"%i", indexPath.row]];
                }
                
                picAddVC.tableId = [NSString stringWithFormat:@"%@", model.tableId]; // [dic valueForKey:@"tableId"]
                picAddVC.pageId = [NSString stringWithFormat:@"%@", model.showFieldArr]; // [dic valueForKey:@"showFieldArr"]
                picAddVC.fromDataArr = self.filedArr;
                picAddVC.fromMangManArr = self.mangManArr;
                picAddVC.fromSendMutDic = self.sendMutDic;
                picAddVC.delegateView = self;
                picAddVC.buttonDic = _buttonDic;
                picAddVC.tNum = _tNum;
                
                _rowNum = indexPath.row;
                
                NSLog(@"%@", picAddVC.fromDataArr);
                [self.navigationController pushViewController:picAddVC animated:YES];
                
            }
            
            return;
        }
        NSString *fieldRole =model.fieldRole; // [dic objectForKey:@"fieldRole"]
        NSInteger num =[fieldRole integerValue];
        if(num==21||num == 20||num==22){
            
            NSMutableDictionary *selectSchoolKeyValueDic = [[NSMutableDictionary alloc]init];
            
            
            NSString *needFilterStr = [NSString stringWithFormat:@"%@", model.needFilter]; // [dic valueForKey:@"needFilter"]
            
            if ([needFilterStr length]>0&&![needFilterStr isEqualToString:@"(null)"]) {
                NSArray *arrNeedFilters = [needFilterStr componentsSeparatedByString:@","];
                
                
                //*** needFilter take out with ":" to divOut
                NSArray *arr;
                BOOL findNeedFilter = NO;
                //*** many needFilters in one string take out the string we wang to use with "valueP"
                for (NSString *needFilterTakeOut in arrNeedFilters) {
                    if ([needFilterTakeOut hasPrefix:@"valuePlug_"]) {
                        
                        NSString *selectSchoolKey = @"";
                        NSString *selectSchoolValue = @"";
                        
                        arr = [[NSString stringWithFormat:@"%@",  needFilterTakeOut]componentsSeparatedByString:@":"];
                        
                        if(arr.count>0)selectSchoolKey = [NSString stringWithFormat:@"%@", arr[0]];
                        NSMutableArray *useThisArr = [[NSMutableArray alloc]init];
                        [useThisArr addObjectsFromArray:_filedArr];
                        [useThisArr addObjectsFromArray:_fromDataArr];

                        for (EditModel *model in useThisArr) { // for one
                            
                            NSString *fieldRoleMoment =[NSString stringWithFormat:@"%@", model.fieldRole]; //[dic1 objectForKey:@"fieldRole"];
                            NSInteger numMoment =[fieldRoleMoment integerValue];
                            
                            NSString *str = [NSString stringWithFormat:@"%@", model.fieldId]; // [dic1 valueForKey:@"fieldId"]
                            //
                            //                }// if one end
#warning 可能会崩溃
                            if ([str isEqualToString:arr[1]]) { // if two
                                
                                findNeedFilter = YES;
                                
                                EditModel *dicForThis= model;
                                NSString *fieldRole= [NSString stringWithFormat:@"%@", dicForThis.fieldRole]; //[dicForThis objectForKey:@"fieldRole"];
                                
                                NSString *fieldId;
                                if(dicForThis.relationTableId!=nil){ // [dicForThis valueForKey:@"relationTableId"]
                                    fieldId= [NSString stringWithFormat:@"%@", dicForThis.dialogField]; //[dicForThis objectForKey:@"dialogField"];
                                    
                                }else{
                                    fieldId= [NSString stringWithFormat:@"%@", dicForThis.fieldId]; //[dicForThis objectForKey:@"fieldId"];
                                    
                                }
                                if(fieldId == nil){
                                    fieldId = [NSString stringWithFormat:@"%@", dicForThis.fieldId]; // [dicForThis objectForKey:@"fieldId"]
                                }
                                NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
                                
#warning tableId may not this
                                NSString *tableId= [_buttonDic objectForKey:@"tableId"];
                                NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
                                
                                
                                NSString *baseStringSend = [NSString stringWithFormat:@"_au_%@_%@_%@",model.relationTableId,pageId,fieldId]; // [dic1 valueForKey:@"relationTableId"]
                                
//                                NSString *strN = [KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:_tString];
//                                NSString *strweirhwei = [KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:_tString];
                                
                                //*** 前提条件下 传送前提条件
                                if((([_fromSendMutDic valueForKey:model.montageName]||[_sendMutDic valueForKey:model.montageName])||[_fromSendMutDic valueForKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:_tString]]||[_sendMutDic valueForKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:_tString]])&& numMoment != 21){
                                    
                                    selectSchoolValue =[NSString stringWithFormat:@"%@", [_sendMutDic valueForKey:dicForThis.montageName]];
                                }else if((_fromMangManArr || _mangManArr) && numMoment == 21){
                                    
                                    NSMutableArray *valueArrs = [[NSMutableArray alloc]init];
                                    
                                    
                                    NSMutableArray *addManyManArr = [[NSMutableArray alloc]init];
                                    [addManyManArr addObjectsFromArray:_mangManArr];
                                    [addManyManArr addObjectsFromArray:_fromMangManArr];
                                    
                                    for ( NSDictionary *dicManyArr in addManyManArr) {
                                        // -------------------------------------------------------
                                        NSString *relationTableId=[NSString stringWithFormat:@"%@",model.relationTableId];
                                        NSString *showFieldArr=[NSString stringWithFormat:@"%@",model.showFieldArr];
                                        NSString *dialogField=[NSString stringWithFormat:@"%@",model.dialogField];
                                        
                                        NSString *fieldOfValue =[NSString stringWithFormat:@"t1_au_%@_%@_%@",relationTableId,showFieldArr,dialogField];
                                        NSString *fieldOfValueFromLastPage =[NSString stringWithFormat:@"t%li_au_%@_%@_%@", _tNum,relationTableId,showFieldArr,dialogField];

                                        
                                        if([dicManyArr valueForKey:fieldOfValue]){
                                            [valueArrs addObject:[dicManyArr valueForKey:fieldOfValue]];
                                        }else if([dicManyArr valueForKey:fieldOfValueFromLastPage]){
                                            [valueArrs addObject:[dicManyArr valueForKey:fieldOfValueFromLastPage]];
                                        }
                                    }
                                    
                                    selectSchoolValue = [NSString stringWithFormat:@"%@", [valueArrs componentsJoinedByString:@","]];
                                    
                                    if([_sendMutDic valueForKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseStringSend andTUseString:self.tString]]&&selectSchoolValue.length<=0){
                                        
                                        
                                        selectSchoolValue = [_sendMutDic valueForKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseStringSend andTUseString:self.tString]];
                                    }
                                }else{
                                    
                                    selectSchoolValue = @"";
                                }
                                
                            }
                            
                            
                            
                        }
                        
                        //*** 关联添加显示
                        if(!findNeedFilter){
                            selectSchoolValue = [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]];
                        }
                        if(selectSchoolKey.length>0)[selectSchoolKeyValueDic setObject:selectSchoolValue forKey:selectSchoolKey];
                        
                    }else{
                        
                    }
                }
                
            }
            
            NSMutableArray *useThisArr = [[NSMutableArray alloc]init];

            [useThisArr addObjectsFromArray:_filedArr];
            [useThisArr addObjectsFromArray:_fromDataArr];

            
            NSMutableArray *addManyManArr = [[NSMutableArray alloc]init];
            [addManyManArr addObjectsFromArray:_mangManArr];
            [addManyManArr addObjectsFromArray:_fromMangManArr];

            
            NSMutableDictionary *sendMutDic = [[NSMutableDictionary alloc]initWithDictionary:_sendMutDic];
            [sendMutDic setValuesForKeysWithDictionary:_fromSendMutDic];
            [_keyValueClass needFilterHave:model andManyManArr:addManyManArr andCurrentPageDataArr:useThisArr andTString:_tString detailDic:_detailDic andTableId:_tableId andSendDic:sendMutDic andReturnBlock:^(NSMutableDictionary *filterDic, NSString *error) {
                
                if (!error) {
                    _selectSchoolKeyValueDic = filterDic;

                }else{
                    [self showLabelWithText:error];
                    return;
                }
                
            }];

            SelectSchoolController *sv =[[SelectSchoolController alloc]init];
            sv.delegateView = self;
            
            if (num == 20) {
                sv.one = YES;
            }else{
                sv.one = NO;
            }
            if([[NSString stringWithFormat:@"%@", model.chooseType] isEqualToString:@"1"]){ // [dic valueForKey:@"chooseType"]
                sv.treeDir = YES;
            }else{
                sv.treeDir = NO;
            }
            
            //*** premiseDic
            sv.premiseDic = selectSchoolKeyValueDic;
            
            NSDictionary *d = model.dialogDataList; // objectForKey:@"dialogDataList"]; //[dic objectForKey:@"dialogDataList"];
            sv.schoolArr = [d objectForKey:@"rows"];
            
            NSString *requestUrl = [NSString stringWithFormat:@"%@%@", self.programaUrl, LISTSVIEWREQUEST_URL];
            
            sv.searchArr = model.dialogSearchSet; //[dic objectForKey:@"dialogSearchSet"];
            NSString *pageId= model.pageDialog; //[dic objectForKey:@"pageDialog"];
            NSString *tableId= model.tableId; //[dic objectForKey:@"tableId"];
            if(tableId == nil){
                tableId = model.relationTableId; //[dic objectForKey:@"relationTableId"];
            }
            sv.pageId = pageId;
            
            sv.tableId = tableId;
            //        sv.searchUrl = [dic objectForKey:@"dialogSearchUrl"];
            
            sv.searchUrl = requestUrl;
            
            //        NSData *dataStr = [dicStr dataUsingEncoding:NSUTF8StringEncoding];
            //        NSDictionary *d2 = [NSJSONSerialization JSONObjectWithData:dataStr options:0 error:nil];
            
            sv.schoolFieldStr = [NSString stringWithFormat:@"%@", model.tableId]; // [dic objectForKey:@"tableId"]
            sv.rowNum = indexPath.row;
            _rowNum = indexPath.row;
            
            [self.navigationController pushViewController:sv animated:YES];
            
        }
        else{
            //   NSString *str= [self fileType:num];
        }
        
        //tableId=13&pageId=137&tmpJsonData=&valuePlug_6672=
    }
    else{
        [cell.titleText becomeFirstResponder];
    }
}

#pragma mark - start and end time click
-(void)startClick:(UIButton *)btn{
    NSLog(@"start");
    //    currTimeBtn = btn;
    [self createPickerView];
}

-(void)createPickerView{
    [self resignFirstResponder];
    withShowPicView.hidden = NO;
    _timeBackImg.hidden = withShowPicView.hidden;
    
    _pickerView.hidden = NO;
}

-(void)endClick:(UIButton *)btn{
    //    currTimeBtn = btn;
    [self createPickerView];
    NSLog(@"end");
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 109/2;
}

-(NSString *)tStringJia{
    NSString *strT = [NSString stringWithFormat:@"t%li", _tNum+1];
    return strT;
}
#pragma mark - UITextFieldDelegate
- (void)textFieldDidBeginEditing:(CustomTextField *)textField{
    focusTextField = textField;
    NSDictionary *dic = [_filedArr objectAtIndex:textField.indexPath.row];
    NSString *fieldRow = [dic valueForKey:@"fieldRole"];
    NSInteger num = [fieldRow integerValue];
    if (num == 6 || num == 7 || num == 12 || num == 13) {
        textField.keyboardType = UIKeyboardTypeNumberPad;
    }else{
        textField.keyboardType = UIKeyboardTypeDefault;
    }
    //    textField.keyboardType = UIKeyboardTypeNumberPad;
    //    NSDictionary *dic= [_filedArr objectAtIndex:textField.indexPath.row];
    //    NSString *fieldRole =[dic objectForKey:@"fieldRole"];
    //    NSInteger num =[fieldRole integerValue];
    //    if(num==21){
    //
    //
    //        NSString *selectSchoolKey = @"";
    //        NSString *selectSchoolValue = @"";
    //
    //        NSString *needFilterStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"needFilter"]];
    //
    //        if ([needFilterStr length]>0&&![needFilterStr isEqualToString:@"(null)"]) {
    //
    //            NSArray *arr = [[NSString stringWithFormat:@"%@", [dic valueForKey:@"needFilter"]]componentsSeparatedByString:@":"];
    //
    //            selectSchoolKey = [NSString stringWithFormat:@"%@", arr[0]];
    //
    //            for (NSDictionary *dic1 in _filedArr) { // for one
    //                NSString *str = [NSString stringWithFormat:@"%@", [dic1 valueForKey:@"fieldId"]];
    ////                if ([str isEqualToString:[NSString stringWithFormat:@"%@", arr[1]]]) { // if one
    ////
    ////                }// if one end
    //#warning 可能会崩溃
    //                if ([str isEqualToString:arr[1]]) { // if two
    //                    NSDictionary *dicForThis= dic1;
    //                    NSString *fieldRole= [dicForThis objectForKey:@"fieldRole"];
    //
    //                    NSString *fieldId;
    //                    if([dicForThis valueForKey:@"relationTableId"]!=nil){
    //                        fieldId= [dicForThis objectForKey:@"dialogField"];
    //
    //                    }else{
    //                        fieldId= [dicForThis objectForKey:@"fieldId"];
    //
    //                    }
    //                    NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
    //                    NSString *tableId= self.tableId;
    //                    NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
    ////                    NSString *relationTableId=[NSString stringWithFormat:@"%@",[dic objectForKey:@"relationTableId"]] ;
    ////                    NSString *showFieldArr=[NSString stringWithFormat:@"%@",[dic objectForKey:@"showFieldArr"]] ;
    //                    //    NSString *showFieldArr=[NSString stringWithFormat:@"%@",[dic objectForKey:@"fieldId"]] ;
    //
    ////                    NSString *dialogField=[NSString stringWithFormat:@"%@",[dic objectForKey:@"dialogField"]] ;
    //
    ////                    NSString *fieldOfNum =[NSString stringWithFormat:@"t0_au_%@_%@_%@_dz",relationTableId,showFieldArr,fieldId];
    //
    ////                    NSString *fieldOfValue =[NSString stringWithFormat:@"t1_au_%@_%@_%@",relationTableId,showFieldArr,dialogField];
    //
    //                    //*** 前提条件下 传送前提条件
    //                    if([_sendMutDic valueForKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]]){
    //
    //                        selectSchoolValue =[NSString stringWithFormat:@"%@", [_sendMutDic valueForKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]]];
    //                    }else{
    //                    selectSchoolValue = @"";
    //                    }
    //
    //                }
    //            }
    //        }
    //
    //        SelectSchoolController *sv =[[SelectSchoolController alloc]init];
    //        if([[NSString stringWithFormat:@"%@", [dic valueForKey:@"chooseType"]] isEqualToString:@"1"]){
    //            sv.treeDir = YES;
    //        }else{
    //            sv.treeDir = NO;
    //        }
    //        if(selectSchoolKey){
    //            sv.premiseKey = selectSchoolKey;
    //        }
    //
    //        if(selectSchoolValue){
    //            sv.premise = selectSchoolValue;
    //        }
    ////        sv.treeDir = YES;
    //
    //        [self.navigationController pushViewController:sv animated:YES];
    ////        NSString *dicStr = [dic objectForKey:@"dialogDataListUrl"];
    ////        NSString *FieldStr = [dic objectForKey:@"dialogFieldUrl"];
    ////        NSString * urlString= [dicStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    ////        NSURL *url=[NSURL URLWithString:urlString];
    ////        NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    ////        //    3.发送请求
    ////        //发送同步请求，在主线程执行
    ////        NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    ////        NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    ////        NSString *str = [dic objectForKey:@"dialogDataList"];
    ////        NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
    ////        NSDictionary *d =[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    //        NSDictionary *d = [dic objectForKey:@"dialogDataList"];
    //         sv.schoolArr = [d objectForKey:@"rows"];
    //
    //        NSString *requestUrl = [NSString stringWithFormat:@"%@%@", self.programaUrl, LISTSVIEWREQUEST_URL];
    //
    //        sv.searchArr = [dic objectForKey:@"dialogSearchSet"];
    //        NSString *pageId= [dic objectForKey:@"pageDialog"];
    //        NSString *tableId= [dic objectForKey:@"tableId"];
    //        sv.pageId = pageId;
    //
    //        sv.tableId = tableId;
    ////        sv.searchUrl = [dic objectForKey:@"dialogSearchUrl"];
    //
    //        sv.searchUrl = requestUrl;
    //
    ////        NSData *dataStr = [dicStr dataUsingEncoding:NSUTF8StringEncoding];
    ////        NSDictionary *d2 = [NSJSONSerialization JSONObjectWithData:dataStr options:0 error:nil];
    //       
    //        sv.schoolFieldStr = [NSString stringWithFormat:@"%@", [dic objectForKey:@"tableId"]];
    //        sv.rowNum = textField.indexPath.row;
    //        _rowNum = textField.indexPath.row;
    //         [textField resignFirstResponder];
    //    }
    //    else{
    ////   NSString *str= [self fileType:num];
    //    }
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    
    
    return NO;
}

-(NSString *)fileType:(NSInteger )num{
    NSString *str = @"";
    switch (num) {
        case 0:case 1:case 2:case 3:case 4:case 5:case 6:
        case 7:case 8:case 9:case 10:case 11:case 12:case 13:
        case 23:case 24:case 25:case 26:case 27:case 28:
            str = @"1";
            break;
        case 14:case 15:
            str = @"2";
            break;
        case 16:
            str = @"3";
            break;
        case 17:
            str = @"4";
            break;
        default:
            break;
    }
    return str;
}


- (BOOL)textFieldShouldBeginEditing:(CustomTextField *)textField{
    //    NSDictionary *dic = [_filedArr objectAtIndex:textField.indexPath.row];
    EditModel *model = [_filedArr objectAtIndex:textField.indexPath.row];
    
    if(model.jsWhereStr){
        
        //        BOOL is = [self textQianTiTiaoJian:dic];
        
        NSString *isN = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_filedArr];
        
        if (![isN isEqualToString:@"YES"]) {
            
            [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", isN]];
            
            return NO;
        }
        
        BOOL is;
        
        if ([isN isEqualToString:@"YES"]) {
            is = YES;
        }else{
            is = NO;
        }

        
        return is;
    }
    return YES;
}


-(void)textFieldDidEndEditing:(CustomTextField *)textField{
    if(![textField.text isEqualToString:@""]){
        
        //        NSDictionary *dic= [_filedArr objectAtIndex:textField.indexPath.row];
        
        EditModel *model= [_filedArr objectAtIndex:textField.indexPath.row];
        
        [self nromalSetKeyValues:model andTextField:textField];
        
    }
    
}



-(void)nromalSetKeyValues:(EditModel *)model andTextField:(CustomTextField *)textField{
    //    NSDictionary *dic= [_filedArr objectAtIndex:textField.indexPath.row];
    NSString *fieldRole= [NSString stringWithFormat:@"%@", model.fieldRole]; //[dic objectForKey:@"fieldRole"];
    //    NSString *fieldId= [dic objectForKey:@"fieldId"];
    //    NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
    //    //*** change the tableId
    //    NSString *tableId= [_buttonDic objectForKey:@"tableId"];
    //    NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
    NSString *role =[NSString stringWithFormat:@"%@",fieldRole];
    BOOL is = [NSString witchRoleis:role withStr:textField.text];
    if(is){
        
        [_sendMutDic setObject:textField.text forKey:model.montageName]; // [self getNorMalKey:dic]
        NSLog(@"%@",_sendMutDic);
        model.true_defaultShowValName = textField.text;
        
        //        [_selectedDic setObject:textField.text forKey:[NSString stringWithFormat:@"%ld", (long)textField.indexPath.row]];
    }
    else{
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil message:@"请输入正确的格式" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
        [alert show];
        textField.text  =@"";
    }
    
}

-(void)currDate{
    NSDate *now = [NSDate date];
    NSLog(@"now date is: %@", now);
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
    
    int year = (int)[dateComponent year];
    int month = (int)[dateComponent month];
    int day = (int)[dateComponent day];
    int hour = (int)[dateComponent hour];
    int minute = (int)[dateComponent minute];
    int second = (int)[dateComponent second];
    
    yeaStr = [NSString stringWithFormat:@"%i", year];
    montStr = [NSString stringWithFormat:@"%i", month];
    daStr = [NSString stringWithFormat:@"%i", day];
    
    NSLog(@"year is: %d", year);
    NSLog(@"month is: %d", month);
    NSLog(@"day is: %d", day);
    NSLog(@"hour is: %d", hour);
    NSLog(@"minute is: %d", minute);
    NSLog(@"second is: %d", second);
    [self pingRun:year-1 Ok:NO];
    [self pingRun:year Ok:NO];
    [self pingRun:year+1 Ok:YES];
    [_pickerView selectRow:1 inComponent:0 animated:YES];
    [_pickerView selectRow:month-1 inComponent:2 animated:YES];
    [_pickerView selectRow:day-1 inComponent:4 animated:YES];
    
    
}
-(void)pingRun:(int)yea Ok:(BOOL)ok{
    if(((yea%4==0)&&(yea%100!=0))||(yea%400==0)){
        NSLog(@"闰年");
        NSString *cityPath=[[NSBundle mainBundle] pathForResource:@"RunYear" ofType:@"plist"];
        monArr=[NSArray arrayWithContentsOfFile:cityPath];
    }
    else
    {
        NSLog(@"平年");
        NSString *cityPath=[[NSBundle mainBundle] pathForResource:@"PingYear" ofType:@"plist"];
        monArr=[NSArray arrayWithContentsOfFile:cityPath];
    }
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:monArr forKey:[NSString stringWithFormat:@"%i", yea]];
    [yeaArr addObject:dic];
    //    NSLog(@"%@", [NSString stringWithFormat:@"%i", yea]);
    //    NSLog(@"%@", monArr);
    //    NSLog(@"%lu", (unsigned long)monArr.count);
    //    NSLog(@"%lu", (unsigned long)yeaArr.count);
    if (ok) {
        [_pickerView reloadAllComponents];
        
    }
}

#pragma mark pickerViewDelegate
//返回组数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerVie{
    return 6;
}
//返回行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    NSLog(@"%li", (long)component);
    if(yeaArr.count<3)return 0;
    //    return ((NSArray *)yeaArr[component]).count;
    if(component == 0){
        return yeaArr.count;
    }else if(component == 1){
        return 1;
        
    }else if (component == 2){
        return 12;
    }else if (component == 3){
        return 1;
    } else if(component == 4){
        //        NSLog(@"%@", yeaArr);
        NSInteger row1=[_pickerView selectedRowInComponent:0];
        NSInteger row2=[_pickerView selectedRowInComponent:2];
        //然后是获取这个行中的值，就是数组中的值
        //        int a = [label.text intValue];
        
        //        int b = [label1.text intValue];
        
        NSDictionary *dic = yeaArr[row1];
        NSArray *arr2 = [dic allKeys];
        NSArray *arr = [dic valueForKey:arr2[0]];
        NSArray *arr1 = arr[row2];
        //        NSLog(@"%@", arr);
        //        NSLog(@"%@", arr1);
        return arr1.count;
    }else{
        return 1;
    }
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    
    return @"2015";
}
//选中row
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    UILabel *label = (UILabel *)[pickerView viewForRow:row forComponent:component];
    NSLog(@"%@", label.text);
    [self textData:label.text andCompoment:component];
    if (component == 2) {
        [_pickerView reloadComponent:4];
    }
    NSLog(@"row:%ld",(long)row);
}

-(void)textData:(NSString *)text andCompoment:(NSInteger)compoment{
    NSLog(@"%@", text);
    if (compoment == 0) {
        yeaStr = text;
    }else if(compoment == 2){
        montStr = text;
    }else if (compoment == 4){
        daStr = text;
    }
    [self testString];
}

-(void)testString{
    if (yeaStr&&montStr&&daStr) {
        NSLog(@"%@", [NSString stringWithFormat:@"%@-%@-%@", yeaStr, montStr, daStr ]);
        //        _pickerView.hidden = YES;
        //        withShowPicView.hidden = YES;
        //        yeaStr = nil;
        //        montStr = nil;
        //        daStr = nil;
    }
}
//设置选取器的字体
- (UILabel *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(50, 10, 150, 50)];
    if(component == 0){
        //        NSArray *arr = [(NSDictionary *)(yeaArr[component]) allKeys];
        ////        NSArray *arr = [(NSDictionary *)(yeaArr[component]) allKeys];
        ////        NSArray *arr = [(NSDictionary *)(yeaArr[component]) allKeys];
        //        NSLog(@"%@", yeaArr);
        //        NSLog(@"%@", arr);
        if(row == 0){
            NSArray *arr = [(NSDictionary *)(yeaArr[component]) allKeys];
            label.text=arr[0];
        }else if(row == 1){
            NSArray *arr = [(NSDictionary *)(yeaArr[1]) allKeys];
            label.text=arr[0];
        }else if(row == 2){
            NSArray *arr = [(NSDictionary *)(yeaArr[2]) allKeys];
            label.text=arr[0];
        }
    }else if (component == 1){
        label.text = @"年";
    } else if(component == 2){
        //        NSArray *arr = [(NSDictionary *)(yeaArr[component]) allKeys];
        label.text=[NSString stringWithFormat:@"%i", (int)row+1];
        
    }else if (component == 3){
        label.text = @"月";
    } else if(component == 4){
        //        NSLog(@"%@", yeaArr);
        NSInteger row1=[_pickerView selectedRowInComponent:0];
        NSInteger row2=[_pickerView selectedRowInComponent:1];
        //然后是获取这个行中的值，就是数组中的值
        //        UILabel *label1 = (UILabel *)[pickerView  viewForRow:row1 forComponent:0];
        //        int a = [label.text intValue];
        
        //        UILabel *label2 = (UILabel *)[pickerView  viewForRow:row2 forComponent:1];
        //        int b = [label1.text intValue];
        
        NSDictionary *dic = yeaArr[row1];
        NSArray      *arr2 = [dic allKeys];
        NSArray *arr = [dic valueForKey:arr2[0]];
        NSArray *arr1 = arr[row2];
        NSLog(@"%@", arr);
        NSLog(@"%@", arr1);
        label.text = arr1[row];
        
        //        label.text = [NSString stringWithFormat:@"%i", (int)row+1];
    }else if (component == 5){
        label.text = @"日";
    }
    
    //    label.text=@"2015";
    label.textAlignment=NSTextAlignmentCenter;
    label.font=[UIFont systemFontOfSize:25];
    return label;
}

-(NSString *)fieldDicToString:(NSArray *)arr{
    NSString *str = @"";
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for(NSDictionary *dic in arr){
        NSArray *a1 =[dic allKeys];
        NSString *value =[dic objectForKey:a1[0]];
        NSString *equal = [NSString stringWithFormat:@"%@=%@",a1[0],value];
        [array addObject:equal];
    }
    str =[array componentsJoinedByString:@"&&"];
    return str;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
